package com.example.jishi.demos.web.controller;

import com.example.jishi.demos.web.entity.WorkLog;
import com.example.jishi.demos.web.service.WorkLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/worklogs")
public class WorkLogController {
    @Autowired
    private WorkLogService workLogService;

    @GetMapping("/list")
    public List<WorkLog> getAllWorkLogs(@RequestParam(required = false) String name,@RequestParam(required = false) String keyword) {
        return workLogService.getAllWorkLogs(name,keyword);
    }

    @GetMapping("/{id}")
    public WorkLog getWorkLogById(@PathVariable int id) {
        return workLogService.getWorkLogById(id);
    }

    @PostMapping("/add")
    public void addWorkLog(@RequestBody WorkLog WorkLog) {
        workLogService.addWorkLog(WorkLog);
    }

    @PutMapping("/update")
    public void updateWorkLog(@RequestBody WorkLog WorkLog) {
        workLogService.updateWorkLog(WorkLog);
    }

    @DeleteMapping("/delete/{id}")
    public void deleteWorkLog(@PathVariable int id) {
        workLogService.deleteWorkLog(id);
    }
}
